﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace KStarProxy
{
    class KStarAPI
    {
        [DllImport("Libs\\KsFtQtPub.dll")]
        public static extern bool KSFTHQPUB_Start(ushort port, StringBuilder msg);

        [DllImport("Libs\\KsFtQtPub.dll")]
        public static extern void KSFTHQPUB_Stop();

        [DllImport("Libs\\KsFtQtPub.dll")]
        public static extern int KSFTHQPUB_GetQuota(KSFT_QUOTA_PUBDATA_ITEM[] dataBuf, int bufSize,
int timeOut, StringBuilder msg);

        [DllImport("Libs\\KsFtQtPub.dll", EntryPoint = "KSFTHQPUB_GetQuota")]
        public static extern int KSFTHQPUB_GetQuota_Byte(byte[] dataBuf, int bufSize,
int timeOut, StringBuilder msg);



        [StructLayout(LayoutKind.Sequential, Pack = 8)]
        public struct KSFT_QUOTA_PUBDATA_ITEM
        {
            public int contract_id;				//由交易品种和交割期算出来的id,对应：id号;
            public int upd_serial;				//行情更新序号，对应：序号
            public int upd_date;				//行情日期,格式：YYYYMMDD
            public int pre_upd_date;				//行情上次更新日期(保留)
            public int pre_upd_serial;				//上次更新时的序号(保留)
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
            public string sys_recv_time;		//行情服务器收到行情的时间，行情服务器唯一维护，格式：HH:MM:SS
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
            public string exchCode;		//交易所代码
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string varity_code;		//品种代码
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
            public string deliv_date;		//交割期
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
            public string chgStatus;	//对应：状态
            //1-2bit表示：买入;3-4bit表示：卖出;
            //5-6bit表示：最新;7-8bit不用;
            //00->新行情    01->低于以前的行情
            //11->高于以前的行情    00->与以前相平
            public double openPrice;				//开盘价
            public double lastPrice;				//最新价
            public double highestPrice;				//最高价
            public double lowestPrice;				//最低价
            public int doneVolume;				//成交量
            public double chgPrice;				//涨跌
            public double upperLimitPrice;			//涨停板
            public double lowerLimitPrice;			//跌停板
            public double hisHighestPrice;			//历史最高价
            public double hisLowestPrice;				//历史最低价
            public int openInterest;				//净持仓
            public double preSettlePrice;				//昨日结算
            public double preClosePrice;				//昨日收盘
            public double settlePrice;				//今日结算
            public double turnover;				//成交金额
            public int preOpenInterest;			//昨日持仓量
            public double closePrice;				//今日收盘
            public double preDelta;				//昨虚实度
            public double currDelta;				//今虚实度
            public double bidPrice1;				//买入价1
            public int bidVolume1;				//买入量1
            public double bidPrice2;				//买入价2
            public int bidVolume2;				//买入量2
            public double bidPrice3;				//买入价3
            public int bidVolume3;				//买入量3
            public double bidPrice4;				//买入价4
            public int bidVolume4;				//买入量4
            public double bidPrice5;				//买入价5
            public int bidVolume5;				//买入量5

            public double askPrice1;				//卖出价1
            public int askVolume1;				//卖出量1
            public double askPrice2;				//卖出价2
            public int askVolume2;				//卖出量2
            public double askPrice3;				//卖出价3
            public int askVolume3;				//卖出量3
            public double askPrice4;				//卖出价4
            public int askVolume4;				//卖出量4
            public double askPrice5;				//卖出价5
            public int askVolume5;				//卖出量5
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
            public string cmbtype; //‘0’或NULL:普通行情
            //‘1’：组合套利行情
            public int derive_bidlot;   //买推导量   组合买入数量
            public int derive_asklot;   //卖推导量   组合卖出数量
        }

    }
}
